<script>
$(document).ready(function(){
    var uceniks = $('.image_upload');
    $.each(uceniks, function(i,n){
    new AjaxUpload('#' + n.id, {action: '/skola.php/ucenik/uploadImage/id/' + n.id, autoSubmit: true, onComplete: function(file, response) { $('#' + n.id).html(response);}});
    });
});
</script>

<?php
  include_stylesheets_for_form($form);
  include_javascripts_for_form($form);
  use_helper('jQuery', 'Form');
?>

<form action="" method="POST">
  <table style="display:inline; float: left;" id='podesavanja_razreda'>
    <?php echo $form ?>
    <tr>
      <td colspan="2">
        <a id="dugme" onclick="document.forms[0].submit(); return false;" href="javascript: void(0)" class="button"><span>Sačuvaj</span></a>
      </td>
    </tr>
  </table>
</form>

<div>
<table cellpadding='0' cellspacing='0' style='padding: 5px; border: 1px solid #000;'>
      <?php
      $i = 0;
      foreach($uceniks as $ucenik)
      {
          if(($i++ % 8) == 0)
            echo "<tr>"?>
        <td style="text-align:center;font-size: 10px;">
          <div class="image_upload" id="uc_<?php echo $ucenik->getId() ?>">
            <?php echo Functions::image($ucenik->getId(), $ucenik->getPol()); ?>
          </div>
          <?php echo mb_substr($ucenik, 0, 12, 'utf-8'); ?>
        </td>
          <?php
          if(($i % 8) == 0)
            echo "</tr>";
      }
      if(($i % 8) != 0)
            echo "</tr>";
           ?>
</table>
</div>

<div id="feedback"></div>
<div id="indicator" style="display: none"><?php echo image_tag("ajax-loading_2.gif", array("alt" => __("Čuva se"))) ?></div>


<?php
$glue = array("CasP", "Cas", "Cas1", "Cas2", "Cas3", "Cas4", "Cas5", "Cas6", "Cas7", "Cas8");
$glue_naziv = array("Predcas", "Nulti", "1. čas", "2. čas", "3. čas", "4. čas", "5. čas", "6. čas", "7. čas", "8. čas");
$i = 1;
foreach($raspored_arr as $rasporeds)
{?>
<table style='margin-top:10px; clear:both;' border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
  <tr>
    <th scope="col">Raspored <?php echo $i++ ?></th>
    <th scope="col">Ponedeljak</th>
    <th scope="col">Utorak</th>
    <th scope="col">Sreda</th>
    <th scope="col">Cetvrtak</th>
    <th scope="col">Petak</th>
    <th scope="col">Subota</th>
  </tr>

<?php
    $k = 0;
    while($k < 10)
    {?>
    <tr>
    <th scope="row"><?php echo $glue_naziv[$k] ?></th>
    <?php
      $j = 1;
      foreach($rasporeds as $dan)
      {
        echo "<td>".select_tag($glue[$k].'_'.$dan['Id'], options_for_select($predmets, $dan[$glue[$k]]), array("class" => "raspored_cas", "onchange" => jq_remote_function(array('form' => 'id=this.id', 'update' => 'feedback', 'url' => 'razred/changeRaspored?razred_id='.$sf_request->getParameter('razred_id'), 'loading'  => '$("#indicator").show()', 'complete' => '$("#indicator").hide()'))))."</td>";
      }
      echo "</tr>";
      $k++;
    }

    echo "</table>";
}
?>